package parser

import (
	"bufio"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"reflect"
)



func PrintHello(){
	fmt.Println("Hello, 我在 utilset 目录下的 utils 包里")
}

func ReadFile(fileName string) (data string) {
	fmt.Println("Hello, 我在 utilset 目录下的 utils 包里")
	dat, err := ioutil.ReadFile("./dmlist.txt")
	check(err)
	fmt.Print(string(dat))
	fmt.Print("ReadFile")
	fmt.Println(reflect.TypeOf(string(dat)))
	fmt.Print(string(dat))
	return string(dat)
}



func check(e error) {
	if e != nil {
		panic(e)
	}
}






func main() {
	data := ReadFile("./dmlist.txt")
	fmt.Print(data)

	dat, err := ioutil.ReadFile("./dmlist.txt")
	check(err)
	fmt.Print(string(dat))

	f, err := os.Open("./dmlist.txt")
	check(err)

	b1 := make([]byte, 5)
	n1, err := f.Read(b1)
	check(err)
	fmt.Printf("%d bytes: %s\n", n1, string(b1[:n1]))

	o2, err := f.Seek(6, 0)
	check(err)
	b2 := make([]byte, 2)
	n2, err := f.Read(b2)
	check(err)
	fmt.Printf("%d bytes @ %d: ", n2, o2)
	fmt.Printf("%v\n", string(b2[:n2]))

	o3, err := f.Seek(6, 0)
	check(err)
	b3 := make([]byte, 2)
	n3, err := io.ReadAtLeast(f, b3, 2)
	check(err)
	fmt.Printf("%d bytes @ %d: %s\n", n3, o3, string(b3))

	_, err = f.Seek(0, 0)
	check(err)

	r4 := bufio.NewReader(f)
	b4, err := r4.Peek(5)
	check(err)
	fmt.Printf("5 bytes: %s\n", string(b4))

	f.Close()
}